import javax.swing.JOptionPane;

import java.util.Random;



public class Game {
	static Random g = new Random();
	//static int monstersKilled = 0;
	static char choice;
	static int mHp, mDp, mAp, mAnum, pHp, pDp, pAp, pAnum, roll, z, damage, bHp, bDp, bAp, bAnum;
	static boolean isHit;
	static trashMob mob;
	static String pCharacter;
	static Boss boss;
	public static void main(String[] args){
		choice = JOptionPane.showInputDialog("Please Choose either Fighter Or Scout").toUpperCase().charAt(0);
		
		if(choice != 'F' && choice != 'S'){
			while(choice != 'F' && choice != 'S'){
				choice = JOptionPane.showInputDialog("Please select only Fighter or Scout").toUpperCase().charAt(0);
			}
		}
		else if(choice == 'S'){
			pCharacter = "Scout";
			playGame(chooseClass("Scout"));	
		}
		else{
			pCharacter = "Fighter";
			playGame(chooseClass("Fighter"));
		}
	}
	
	public static Player chooseClass(String thing){
		
		if(thing == "Fighter"){
			Fighter fighter = new Fighter();
			pHp = fighter.getHp();
			pDp = fighter.getDp();
			pAp = fighter.getAp();
			pAnum = fighter.getAnum();
			return fighter;
		}
		else{
			Scout scout = new Scout();
			pHp = scout.getHp();
			pDp = scout.getDp();
			pAp = scout.getAp();
			pAnum = scout.getAnum();
			return scout;
		}
	}

	public static void playGame(Player character){
		int monstersKilled = 0, bossKilled = 0;
		mob = (trashMob) genMonster();
		while(monstersKilled <= 10 && bossKilled <=1 ){
			z = g.nextInt(2);
			if(z == 0){//players turn
				System.out.println("player if");
				hit(z);
				System.out.println("player if, now mobs turn");
				hit(1);//now mobs turn

			}
			else if(z == 1){//mobs turn
				System.out.println("mob if");
				hit(z);
				
			}
			
				System.out.println("mob if,  now players turn");
				hit(0);//now players turn

			if(mHp <= 0){
				JOptionPane.showMessageDialog(null, "You have done killed the monster!");
				System.out.println("You have done killed the monster!");
				monstersKilled++;
				pHp += 10;
				if(monstersKilled != 10){
				mob = (trashMob) genMonster();
				}
			}
			else if(pHp <= 0){
				JOptionPane.showMessageDialog(null, "You have died RNG better fool!");
				System.exit(0);
			}
				
				
			if(monstersKilled == 10){
				System.out.println("Here comes the boss!");
				JOptionPane.showMessageDialog(null, "Here Comes the Boss!");
				boss = (Boss) genBoss();	
			}
		}
	
	}
	public static void hit(int x){
		if(x == 0){//player attacking
			if(g.nextInt(20)+5 >= mDp){
					for(int i = 0; i != pAnum; i ++){
						damage = g.nextInt(pAp)+1;
						mHp -= damage; 
						JOptionPane.showMessageDialog(null, "You have done " + damage + " damage to the monster!" + mHp);
						System.out.println("You have done " + damage + " damage to the monster! " + mHp);
					}//end scout hits
			}//end hit check
			else{//not hit
				JOptionPane.showMessageDialog(null, "You have missed ");
				System.out.println("you missed!");
			}
		}//end player attack

		else if(x == 1){//mob attacking
			if( g.nextInt(20)+5 >= pDp){
				System.out.println("Mob has tried to hit");
				for(int i = 0; i < mAnum; i ++){
					System.out.println("Mob has entered hit loop");
					damage = g.nextInt(mAp)+1;
					pHp -= damage; 
					System.out.println("You have taken " + damage + " you have " + pHp + "left.");
					JOptionPane.showMessageDialog(null, "You have taken " + damage + " you have " + pHp + "left.");
				}
			}
			
			else{//not hit
				JOptionPane.showMessageDialog(null, "mob missed");
				System.out.println("mob missed!");
			}
			
		}//end mob attack
	}//end is hit
				
	public static Monster genMonster(){
		trashMob mob = new trashMob();
		mHp = mob.getHp();
		mDp = mob.getDp();
		mAp = mob.getAp();
		mAnum = mob.getAnum();
		return mob;
	}
	public static Monster genBoss(){
		Boss boss = new Boss();
		mHp = boss.getHp();
		mDp = boss.getDp();
		mAp = boss.getAp();
		mAnum = boss.getAnum();
		return boss;
		
	}
	
	}
